package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.BaseContext;
import com.itheima.reggie.common.R;
import com.itheima.reggie.pojo.Orders;
import com.itheima.reggie.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    /**
     *提交订单
     */
    @PostMapping("/submit")
    public R<String> submits(@RequestBody Orders orders){
        ordersService.submit(orders);
        return R.success("添加成功");
    }
    /**
     * 分页查询（未讲）
     */
    @GetMapping("/userPage")
    public R<Page<Orders>> page(@RequestParam Integer page,@RequestParam Integer pageSize){
        Page<Orders> ordersPage=new Page<>(page,pageSize);
        QueryWrapper<Orders> ordersQueryWrapper=new QueryWrapper<>();
        ordersQueryWrapper.eq("user_id", BaseContext.getCurrentId());
        Page<Orders> page1 = ordersService.page(ordersPage, ordersQueryWrapper);
        return R.success(page1);
    }
}
